#include "game.h"

game::game(void)
{
}

game::~game(void)
{
}
void game::init(ifstream &fi)
{
	// Init Map
	charMap.resize(4);
	locationMap.resize(4);
	for(int i = 0; i < 4; i++)
	{
		charMap[i].resize(4);
		locationMap[i].resize(4);
	}

	// Read start point
	fi >> xStartPoint;
	fi >> yStartPoint;

	// Init current point
	xCurrentPoint = xStartPoint;
	yCurrentPoint = yStartPoint;

	// Read Map
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < 4; j++)
			fi >> charMap[i][j];

	// Write Map
	for(int i = 0; i < 4; i++)
	{
		for(int j = 0; j < 4; j++)
		{
			cout << charMap[i][j] << " ";			
		}
		cout << endl;
	}

	// Read
	string name;
	int life;
	int atack;
	int defence;
	bool isStar;

	// Init Map
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < 4; j++)
		{
			switch (char(charMap[i][j]))
			{
			case 'm':
				{
				fi >> name;
				fi >> life;
				fi >> atack;
				fi >> defence;
				fi >> isStar;
				locationMap[i][j] = new monster(name, life, atack, defence, isStar);
				}
				break;
			case 'p':
				{
				char temp[1000];
				string question = "";
				string answer = "";
				fi.getline(temp,1000);
				for(int i=0; i < 5; i++)
				{
					fi.getline(temp,1000);
					question = question + temp + "\n";
				}
				fi.getline(temp,1000);
				answer = temp;
				fi >> isStar;
				locationMap[i][j] = new puzzle(question, answer, isStar);
				}
				break;
			default:
				locationMap[i][j] = new location();
				break;
			}
		}

	string playerName;
	int playerAbility;
	cout << "Please enter your personal information!\n";
	cout << "Name: ";
	cin >> name;
	try
	{
		cout << "Ability: ";
		cin >> playerAbility;
	}
	catch (exception ex)
	{
		playerAbility = 1;
	}
}
bool game::moveLeft()
{
	if(yCurrentPoint-1 < 0)
		return false;
	else
	{
		yCurrentPoint--;
		return true;
	}
}
bool game::moveRight()
{
	if(yCurrentPoint+1 > 4)
		return false;
	else
	{
		yCurrentPoint++;
		return true;
	}
}
bool game::moveUp()
{
	if(xCurrentPoint-1 < 0)
		return false;
	else
	{
		xCurrentPoint--;
		return true;
	}
}
bool game::moveDown()
{
	if(xCurrentPoint+1 > 4)
		return false;
	else
	{
		xCurrentPoint++;
		return true;
	}
}